<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改工位</title>
    <style>
        .wu-pos-a {
            box-sizing: border-box;
            padding-top: 39px;
            width: 20%;
            left: auto;
            right: 0;
        }
    </style>
</head>
<body>
<div class="pos-r">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        基础设置
        <span class="c-gray en">&gt;</span>
        活动配置
        <span class="c-gray en">&gt;</span>
        修改工位
    </nav>
    <div style="margin-right:22%">
        <div class="page-container">
            <form action="" method="post" class="form form-horizontal" id="store-form-member-edit">
                <input type="text" class="form-control" value="" style="display: none;" id="store-edit-shopId" name="storeId">
                <input type="text" class="form-control" value="" style="display: none;" id="store-edit-array" name="array">
                <div class="form-group">
                    <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>门店名称：</label>
                    <div class="formControls col-xs-4 col-sm-4">
                        <input type="text" class="form-control" value="" placeholder="必填项" id="store-edit-storeName" name="storeName">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>门店编号：</label>
                    <div class="formControls col-xs-4 col-sm-4">
                        <input type="text" class="form-control" value="" placeholder="必填项" id="store-edit-storeNumber" name="storeNumber">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>工位名称：</label>
                    <div class="formControls col-xs-4 col-sm-4">
                        <input type="text" class="form-control" value="" placeholder="必填项" id="store-edit-stationName" name="stationName">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>工位数量：</label>
                    <div class="formControls col-xs-4 col-sm-4">
                        <input type="text" class="form-control" value="" placeholder="必填项" id="store-edit-stationNumber" name="stationNumber">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <input onclick="merchantStoreStationEditFun.submitAction();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    //门店管理，添加服务
    var merchantStoreStationEditFun;

    merchantStoreStationEditFun = {
        init: function () {
            let _this = this;
            _this.StationType();
            var shopId = sessionStorage.getItem("station-stationName");
            _this.modify(shopId);
            _this.bootstrapvalidatorForm();

        },
        modify: function (index) {
            debugger
            var _this = this;
            $.ajax({
                type: "get",
                url: "biz/getShopByShopId",
                async: false,
                data: {stationName: index},
                dataType: "json",
                success: function (result) {
                    if (result.state) {
                        var data = result.data;
                        $("#store-edit-storeName").val(data.storeName);
                        $("#store-edit-storeNumber").val(data.storeNumber);
                        $("#store-edit-stationName").val(data.stationName);
                        $("#store-edit-stationNumber").val(data.stationNumber);
                        $("#store-edit-shopId").val(data.storeId);
                        var biz_type = data.bizType;
                        $("#edit-type-" + (biz_type + 1)).prop("checked", true);
                        var state = data.bizState;
                        $("#edit-state-" + (state + 1)).prop("checked", true);
                        var ddd = $("#edit-sysUserIds").select2();    //获取selectid
                        ddd.val(data.sysUserId).trigger("change");    //设置 value 为four的 option 为选中状态
                        var ddds = $("#edit-roleIds").select2();    //获取selectid
                        ddds.val(data.roleId).trigger("change");    //设置 value 为four的 option 为选中状态

                        $("#editShopImg").fileinput("clear");
                        var resList = data.imgList;
                        if (resList != null) {
                            var len = resList.length;
                            var width = "85px";
                            if (len == 1) {
                                width = "160px";
                            }
                            var img = new Array();
                            for (var i = 0; i < len; i++) {
                                img.push("<img src='files" + resList[i]["url"] + "' eid='" + resList[i]["urlId"] + "' class='file-preview-image' style='width:" + width + ";height:" + width + ";' onclick='window.open(this.src)'>");
                            }
                            $("#editShopImg").fileinput("refresh", {initialPreview: ""});//必加多个资源有重复图片
                            $("#editShopImg").fileinput("refresh", {initialPreview: img});
                            $("#store-form-member-edit").find(".file-thumbnail-footer").remove();
                            $("#store-form-member-edit").find(".file-drop-zone-title").remove();
                            $("#store-form-member-edit").find(".file-preview-frame").css("height", "100px");
                        }
                    }
                    else {
                        alert(result.message);
                    }
                },
                error: function () {
                    alert("error");
                }
            });
            _this.loadTreeChecked(index);
        },
        //表单提交
        submitAction: function () {
            //bootstrap验证
            var bootstrapValidator = $("#store-form-member-edit").data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid())
                $("#store-form-member-edit").submit();
            else return;




            var nodes = treeObj.getCheckedNodes(true);//在提交表单之前将选中的checkbox收集
            var array = new Array();
            for (var i = 0; i < nodes.length; i++) {
                array.push(nodes[i].id);
            }
            $("#store-edit-array").val(array);

            //提交
            $.ajax({
                type: "GET",
                url: "biz/modifyBizShop",
                data: $("#store-form-member-edit").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        if (isChange) {//有图片上传的
                            extData = {"typeId": "store_id", "relateId": data.data};
                            $("#editShopImg").fileinput("upload");
                        }
                        layer.msg(data.message, {icon: 1});
                        //关闭新增窗口
                        removeIframe();
                        merchantStoreStationEditFun.searchAction();
                    } else {
                        $("#store-edit-usernameSpan").text(data.message);
                    }
                },
                error: function () {
                    alert("error");
                }
            });
        },
        //bootstrap验证
        bootstrapvalidatorForm: function () {
            $('#store-form-member-edit').bootstrapValidator({
                message: 'This value is not valid',
                excluded : [':disabled'],
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    shopName: {
                        validators: {
                            notEmpty: {
                                message: '门店名称不能为空'
                            },
                            stringLength: {
                                min: 2,
                                max: 100,
                                message: '门店名称长度必须在2到100位之间'
                            }
                        }
                    },
                    shopNo: {
                        validators: {
                            notEmpty: {
                                message: '门店编号不能为空'
                            },
                            stringLength: {
                                min: 2,
                                max: 20,
                                message: '门店编号长度必须在2到20位之间'
                            }
                        }
                    },
                }
            });
        }

    };

    var extData;
    var isChange;
    $("#editShopImg").fileinput({
        language: "zh", //设置语言
        uploadUrl: "file/upload", //上传的地址
        allowedFileExtensions: ["jpg", "png", "gif"],//接收的文件后缀
        maxFileCount: 5,
        overwriteInitial: false,
        initialCaption: "请上传商品图片，第一张为封面图片",//文本框初始话value
        showUpload: false,//是否显示上传按钮
        showRemove: false,//是否显示删除按钮
        showCaption: true,//是否显示输入框
        browseClass: "btn btn-primary", //按钮样式
        enctype: "multipart/form-data",
        showPreview: true,
        uploadAsync: false,//多图片一次上传
        maxSize: 1024,//单位kb
        allowedPreviewTypes: ["image"],
        uploadExtraData: function () {
            return extData;
        }
    }).on("fileuploaded", function (event, data) {
        if (data.response.success == 0) {
            base.success("新增成功！");
            base.closeTab("新增商品");
        }
        else {
            base.error("新增成功，图片上传失败");
        }
    }).on("change", function (event) {
        isChange = true;
    }).on("fileloaded", function () {
        // $("#form-member-add").find(".file-thumbnail-footer").remove();
        // $("#form-member-add").find(".file-drop-zone-title").remove();
    });

    merchantStoreStationEditFun.init();
</script>
</body>
</html>